<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * @package  	PyroCMS
 * @subpackage  Categories
 * @category  	Module
 * @author  	PyroCMS Dev Team
 */
class Admin_Appearance extends Admin_Controller {

	/**
	 * The current active section
	 * @access protected
	 * @var int
	 */
	protected $section = 'escort-appateance';
	protected $_ci;
	/**
	 * The constructor
	 * @access public
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();
		
		$this->_ci = &get_instance();
		$this->lang->load('be_escort');
		$this->lang->load('be_escort_appearance');
	}
	
	/**
	 * Index method, lists all categories
	 * @access public
	 * @return void
	 */
	public function index($id)
	{
		$id OR redirect('admin/be_escort');
		
		$escort = $this->_ci->escort_entity->init('id', $id);
		$user = $this->_ci->user_entity->init('id', $escort->getUserId());
		$lockedEscort = $this->_ci->locked_escort_entity->init('escort_id', $id);
		if(!$lockedEscort){
			$this->_ci->locked_escort_entity->createNewLockedEscortEntity($id);
			$lockedEscort = $this->_ci->locked_escort_entity->init('escort_id', $id);
		}
		
		if(!$escort || !$user){
			die();
		}
		$this->data['escort'] = $escort;
		$this->data['user'] = $user;
		$this->data['lockedEscort'] = $lockedEscort;
		$this->pyrocache->delete_all('modules_m');
		$this->load->view('admin/appearance/index', $this->data);
	}
	public function save(){
		$result = array();
		$result['result'] = true;
		$escortId = $this->input->post('escort_id');
		$escort = $this->_ci->escort_entity->init('id',$escortId);
		$lockedEscort = $this->_ci->locked_escort_entity->init('escort_id', $escortId);
		//$escort = new CI_Escort_entity();
		$escort->setHairColorId($this->input->post('hair_color_id', TRUE));
		$escort->setHairSizeId($this->input->post('hair_long_id', TRUE));
		$escort->setHairStyleId($this->input->post('hair_style_id', TRUE));
		$escort->setEyeId($this->input->post('eye_id', TRUE));
		$escort->setHeight($this->input->post('height_id', TRUE));
		$escort->setWeight($this->input->post('weight_id', TRUE));
		$escort->setMeasure1($this->input->post('measure1_id'));
		$escort->setMeasure2($this->input->post('measure2_id', TRUE));
		$escort->setMeasure3($this->input->post('measure3_id', TRUE));
		$escort->setPublicHair($this->input->post('public_hair', TRUE));
		$escort->setPublicEye($this->input->post('public_eye', TRUE));
		$escort->setPublicHeight($this->input->post('public_height', TRUE));
		$escort->setPublicWeight($this->input->post('public_weight', TRUE));
		$escort->setPublicMeasures($this->input->post('public_measures', TRUE));
		$escort->adminUpdate();

		//$lockedEscort = new CI_Locked_escort_entity();
		$lockedEscort->setLockedHair($this->input->post('locked_hair'));
		$lockedEscort->setLockedEye($this->input->post('locked_eye'));
		$lockedEscort->setLockedHeight($this->input->post('locked_height'));
		$lockedEscort->setLockedWeight($this->input->post('locked_weight'));
		$lockedEscort->setLockedMeasures($this->input->post('locked_measures'));
		$lockedEscort->update();
		
		
		$result['message'] = lang('escort_be_escort_appearance_update_success');
		echo json_encode($result);
	}
}